import driver.dvars as dvars
import driver.cm19aDriver as cm       

def sendCommand( command, command2=None, command3=None):
    print "In send command"
    if command2 == None and command3 == None:
        print "Old command"
        print command[0]
        message = [None, None, None]
        if command[0] == '+':
            message[2] = 'On'
        elif command[0] == '-':
            message[2] = 'Off'
        else:
            return False, ""
        message[0] = command[1]
        message[1] = command[2]
    elif command3 == None:
        print "bad command"
        message = "Bad Command"
    else: 
        print "New command"
        message = command.split(" ", 3)
    print message, len(message)
    if not len(message) == 3:
        message = message+': '+command+'\n'
        return False, message
    if(dvars.cm19a == None):
        message = "****USB Device is not initialised****\n"
        return False, message
    elif(dvars.cm19a.initialised):
        result = dvars.cm19a.send(message[0], message[1], message[2])
        message = message[0]+' '+message[1]+' ' +message[2]+'\n'
        return True, message
    else:
        message = "****USB Device is not initialised****\n"
        return False, message
